<template>
  <div class="employee">
    <v-head :userName="userName"></v-head>
    <section class='section'>
        <div class="emp_section">
          <div class="emp_top">
            <emp-info class="emp_info" :leaderList="leaderList" :srcImg="srcImg" :reportPlatform="reportPlatform" :leaderPortal="leaderPortal" :holidayPlatform="holidayPlatform" :urlTarget="urlTarget" :emplInfo="emplInfo" :applyLeavePlatform="applyLeavePlatform" ></emp-info>
            <emp-approval :tab.sync='tab1' :tabNumA.sync="tab1Num" :tabNumR.sync="tab2Num" class="emp_approval"></emp-approval>
          </div>
          
          
          <div class="middle_con">
              <leave-vacation ref="vacation"></leave-vacation>
              <leave-nav :leaderList="leaderList" :reportPlatform="reportPlatform" :leaderPortal="leaderPortal" :holidayPlatform="holidayPlatform" :urlTarget="urlTarget" :emplInfo="emplInfo" :applyLeavePlatform="applyLeavePlatform"></leave-nav>
          </div>

          <leave-table ref="tableDept"></leave-table>

        </div>
        <div v-if="tuichu" @click="clearToken" style="z-index:100;position:fixed;top:50%;right:0;width:80px;height:80px;line-height:80px;text-align:center;border-radius: 50%;color:#fff;background-color: #0066CC;">切换用户</div>
    </section>
  </div>
</template>

<script>
//import Axios from "axios";
import Vue from "vue";
import { Tabs } from "element-ui";



import EmpInfo from '@/components/employee/empInfo'
import EmpApproval from '@/components/employee/EmpApproval'
// import EmpList from '@/components/employee/EmpList'
import EmpRecruit from '@/components/employee/EmpRecruit'
import Head from '@/components/employee/header'

import leaveVacation from '@/components/employee/leave_vacation';
import leaveTable from '@/components/employee/leave_table';
import leaveNav from '@/components/employee/leaveNav';
//const EmpInfo = r => require.ensure([],() => r(require('@/components/employee/empInfo')),'empInfo');
//const EmpApproval = r => require.ensure([],() => r(require('@/components/employee/EmpApproval')),'EmpApproval');
//const EmpList = r => require.ensure([],() => r(require('@/components/employee/EmpList')),'EmpList');
//const EmpRecruit = r => require.ensure([],() => r(require('@/components/employee/EmpRecruit')),'EmpRecruit');
//const Head = r => require.ensure([],() => r(require('@/components/employee/header')),'header');


Vue.use(Tabs);

export default {
  name: "employee",
  data() {
    return {
      emplInfo: [],
      appointList: [],
      noticeList: [],
      recruitList: [],
      tab1:[],
      tab2Num:0,
      tab1Num:0,
      userName:null,
      srcImg:null,
      urlTarget:'',
      reportPlatform:null,
      leaderPortal:null,
      holidayPlatform:null,
      applyLeavePlatform:null,
      leaderList:[],
      tuichu:location.hostname === '10.5.0.137' || location.hostname === 'localhost' || location.hostname === '127.0.0.1'

    };
  },
  methods: {
    getEmplid: function(keyToValue) {
      var url = window.location.search;
      if (url.indexOf("?") != -1) {
        var str = url.substr(1);
        var strs = str.split("&");
        // var keys = [],values = [];
        for (var i = 0; i < strs.length; i++) {
          var splitKey = strs[i].split("=");
          if (keyToValue === splitKey[0]) {
            return splitKey[1];
            // break;
          }
        }
      }
    },
    clearToken:function(){
				localStorage.clear();
				location.reload();
    },
   	getWaitAppro:function(){
      let params = {
        pageNo: 1,
        pageSize: 3
      }
      this.Axios
        .Post(this.URL.AuditBylist.url, params)
        .then((res) => {
          this.tab1 = res.data.datas;
          this.tab1Num = res.data.total || 0;
				
        })   		
   	},
   	getDoneAprro:function(){
       let params = {
        pageNo: 1,
        pageSize: 3,
      }
      this.Axios
        .Post(this.URL.findCopyToMeFlow.url, params)
        .then((res) => {
          this.tab2 = res.data.datas;
          this.tab2Num = res.data.total || 0;
          
        })
  		
   	},
   	
   	
   	initAjaxS:function(){

            this.Axios.Post(this.URL.findByAgentId.url)
                .then((res)=>{
                    this.leaderList = res.data.datas || [];
                })    

            // this.Axios.Post(this.URL.queryList.url, {}).then(res => {
            //   this.appointList = res.data.datas.appointList; // 任免列表
            //   this.noticeList = res.data.datas.noticeList; // 公示列表
            //   this.recruitList = res.data.datas.recruitList; // 招聘列表
            // });
        
            // 查看员工信息
            this.Axios.Post(this.URL.getEmployeeDetail.url).then(res => {
              this.emplInfo = res.data.datas.info[0]; // 员工信息
            });

            Vue.nextTick(()=>{

                this.$refs.vacation.getVacation();
                this.$refs.vacation.getVacationDetail();
                //本部门休假
                this.$refs.tableDept.getTableData();
            })

						//获取审批详情
						this.getWaitAppro();
						this.getDoneAprro();

   	}
  },
  beforeCreate(){

	
  },
  created() {

		 if (location.hash.indexOf('target') < 0 && location.hash.split('?').length>1) {

		
			   		 localStorage.clear();
			   	   var params = {};
			   	   var arr = location.hash.split('?')[1].split('&');
					   arr.forEach(function(val,index,arr){
					       var keyArr = val.split('=');
					       var key = keyArr[0];
					       var value = keyArr[1];
					       params[key] = value;
					   });
					   params.url = 'https://m2.cmhk.com/PSP/sso';
					   
		   			 localStorage.setItem('para',JSON.stringify(params));
		    
		    
		    
					    this.Axios.Post(this.URL.loginProduct.url,params).then(res=>{
					        
					        if (res.data.status === 1) {
					            			        		
					            var name = res.data.datas.user.username;
					            var id = res.data.datas.user.userid;
					            var token = res.data.token;
					            var ldmh = res.data.ldmh;
					            
					            
					            
					            this.leaderPortal = res.data.datas.leaderPortal;
					            this.reportPlatform = res.data.datas.reportPlatform;
					            this.holidayPlatform = res.data.datas.holidayPlatform;
					            this.userName = name;
                      this.applyLeavePlatform = res.data.datas.applyLeavePlatform;
                      var superCode = res.data.datas.superCode
					           
					
											
											//获取图片
											this.srcImg = this.Axios.baseURI + this.URL.getLoginUserImg.url + "?token=" + token;  									
											localStorage.setItem('token',token);
                      
											this.initAjaxS();
				
					       
					            localStorage.setItem('userName',name);
					            
					            localStorage.setItem('leaderPortal',this.leaderPortal );
					            localStorage.setItem('reportPlatform',this.reportPlatform);
					            localStorage.setItem('holidayPlatform',this.holidayPlatform);					
                      localStorage.setItem('applyLeavePlatform',this.applyLeavePlatform);	
                      localStorage.setItem('superCode',superCode)				
					
					        } 
					
					
					    })	
					   
					   
			   
		 } else {

					this.initAjaxS();

          if (localStorage.getItem('leaderPortal')) {
              this.leaderPortal =   Number(localStorage.getItem('leaderPortal'));
          }
          if (localStorage.getItem('reportPlatform')) {
              this.reportPlatform =   Number(localStorage.getItem('reportPlatform'));
          }
		    	if (localStorage.getItem('userName')) {
              this.userName = localStorage.getItem('userName');
          }
		    	if (localStorage.getItem('holidayPlatform')) {
              this.holidayPlatform = Number(localStorage.getItem('holidayPlatform'));
          }		      
		    	if (localStorage.getItem('applyLeavePlatform')) {
              this.applyLeavePlatform = Number(localStorage.getItem('applyLeavePlatform'));
          }		  
					//获取图片
					this.srcImg = this.Axios.baseURI + this.URL.getLoginUserImg.url + "?token=" + localStorage.getItem('token');  
	   }

    
 
		

    
    

	

    // this.Axios.Post(this.URL.queryList.url, {}).then(res => {
    //   this.appointList = res.data.datas.appointList; // 任免列表
    //   this.noticeList = res.data.datas.noticeList; // 公示列表
    //   this.recruitList = res.data.datas.recruitList; // 招聘列表
    // });

    // // 查看员工信息
    // this.Axios.Post(this.URL.getEmployeeDetail.url).then(res => {
    //   this.emplInfo = res.data.datas.info[0]; // 员工信息
    // });



    
  },
  components: {
    EmpInfo,
    EmpApproval,
    EmpRecruit,
    "v-head": Head,
    leaveVacation,
    leaveTable,
    leaveNav,
  },
  mounted() {}
};
</script>

<style scoped>
	html body{
		background-color: #ecf0f5;
	}	
	
	
.employee {
  width: 100%;
}
.employee:before{
	content:' ';
	position: fixed;
	top:0;
	bottom:0;
	left:0;
	right:0;
	background-color: #ecf0f5;
	z-index:-1;
}
.section {
  margin-top: 50px;
}
.emp_head {
  height: 50px;
  background: #3c8dbc;
  line-height: 50px;
  text-align: center;
  color: #fff;
}
.emp_section {
  box-sizing: border-box;
  -moz-box-sizing: border-box; /* Firefox */
  -webkit-box-sizing: border-box; /* Safari */
  padding: 30px 50px;

}
.emp_top {
  overflow: hidden;
}
.emp_info {
  width: 66%;
  background: #fff;
  height: 250px;
  float: left;
}
.emp_approval {
  width: 33%;
  background: #fff;
  height: 250px;
  float: right;
}
.emp_lists {
  margin-top: 12px;
  overflow: hidden;
}
.emp_lists .emp_item {
  width: 33.3%;
  float: left;
  background: #fff;
  height: 360px;
}
.emp_lists .emp_item .contentList {
  margin: 20px 0;
  border-right: 1px solid #ecf0f5;
}
.emp_lists .emp_item .border_none {
  border-right: 0;
}
.emp_lists .emp_item .contentList >h2{
    font-size: 16px;
    margin:10px 0px -30px 30px;
}


@media screen and (max-width: 1100px) {
    div.emp_section {
      padding: 30px 20px;
    }
    div.Emp_approval .el-tabs__item{
        padding: 0 24px;
    }
}	

@media screen and (max-width: 1040px) {
    div.emp_top{
      overflow: hidden;
      clear: both;
    }
    div.emp_top > div{
        float: left;
        width:100%;
    }
    div.emp_top > div.Emp_approval{
        margin-top:10px;
    }
}	

</style>
<style>
@media screen and (max-width: 680px) {

    .info_img{
        width:140px !important;
    }
    .info_txt{
        width: calc(100% - 160px)!important;
    }

}
@media screen and (max-width: 1200px) {

    .employee .Emp_approval .el-tabs__item{
        padding: 0 24px ;
    }
}	

</style>
<style>
	@charset "UTF-8";.el-message{box-shadow:0 2px 4px rgba(0,0,0,.12),0 0 6px rgba(0,0,0,.04);min-width:300px;padding:10px 12px;box-sizing:border-box;border-radius:2px;position:fixed;left:50%;top:20px;-ms-transform:translateX(-50%);transform:translateX(-50%);background-color:#fff;transition:opacity .3s,transform .4s;overflow:hidden}.el-message .el-icon-circle-check{color:#13ce66}.el-message .el-icon-circle-cross{color:#ff4949}.el-message .el-icon-information{color:#50bfff}.el-message .el-icon-warning{color:#f7ba2a}.el-message__group{margin-left:38px;position:relative;height:20px;line-height:20px;display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center}.el-message__group p{font-size:14px;margin:0 34px 0 0;white-space:nowrap;color:#8391a5;text-align:justify}.el-message__group.is-with-icon{margin-left:0}.el-message__img{width:40px;height:40px;position:absolute;left:0;top:0}.el-message__icon{vertical-align:middle;margin-right:8px}.el-message__closeBtn{top:3px;right:0;position:absolute;cursor:pointer;color:#bfcbd9;font-size:14px}.el-message__closeBtn:hover{color:#97a8be}.el-message-fade-enter,.el-message-fade-leave-active{opacity:0;-ms-transform:translate(-50%,-100%);transform:translate(-50%,-100%)}
</style>

<style>
.employee .leave-vacation{
  width:66%;
  display: inline-block;
  min-height:320px;
}
.employee .pageNav{
  width:33%;
  overflow: hidden;
  clear: both;
  position: relative;
  height:100%;
  margin-top:1%;
  background-color:#fff;
  float:right;
  min-height:320px;
}
.employee .middle_con{
  overflow: hidden;
}
</style>

